package com.autcar.training.controller;

import com.autcar.training.VO.OrderRequest;
import com.autcar.training.dao.OrderMapper;
import com.autcar.training.entity.FeedBack;
import com.autcar.training.entity.Order;
import com.autcar.training.service.FeedBackService;
import com.autcar.training.service.InsuranceService;
import com.autcar.training.service.OrderService;
import com.autcar.training.service.OrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.ListResourceBundle;

/**
 * @ProjectName: training
 * @Package: com.autcar.training.controller
 * @ClassName: OrderController
 * @Author: YHHHH
 * @Description: 订单控制类
 * @Date: 2020/8/29 16:27
 * @Version: 1.0
 */
@RestController
public class OrderController {

    @Resource
    private OrderServiceImpl orderService;

    @Resource
    private FeedBackService feedBackService;

    @Resource
    private InsuranceService insuranceService;

    /*
    查询所有订单
     */
    @GetMapping("/orderList")
    public List<Order> orderList(){
        List<Order> allOrder = orderService.findAllOrder();
        return allOrder;
    }

    /*
    增加一个订单
     */
    @PostMapping("/addOrder")
    public String addOrder(@RequestBody OrderRequest orderRequest){
        orderService.addOrder(orderRequest);
        return null;
    }

    /*
    删除一个订单
     */
    @GetMapping("/deleteOrder/{id}")
    public String deleteOrder(@PathVariable("id")Integer id){

        Order order = orderService.findOrderById(id);
        FeedBack feedBack = feedBackService.selectByOid((String.valueOf(order.getId())));
        int i = orderService.deleteOrder(id);
        feedBackService.deleteFeedBackById(feedBack.getId());
        return null;
    }

    /*
    /通过订单号查看订单
     */
    @GetMapping("/OrderFindById/{id}")
    public Order findById(@PathVariable("id")Integer id){
        Order orderById = orderService.findOrderById(id);
        return orderById;
    }


    /*
    修改订单
     */
    @RequestMapping("/updateOrder")
    public String updateOrder(@RequestBody Order order){
        int i = orderService.updateOrder(order);
        return null;
    }

    /**
     * 根据客户名称查询订单
     */
    @GetMapping("/findByName/{name}")
    public List<Order> findByCustomerName(@PathVariable String name){
        List<Order> list = orderService.findByCustomerName(name);
        return list;
    }



}
